// pages/homework/published_homework/published_detail/index.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    homework:{},
    length:'',
    te_url:'https://www.yunmosf.top/storage/job/publish',
    st_url:'https://www.yunmosf.top/storage/job/hand_in',
    homework_list:[
      {
        nick_name:'',
        answer_id:'',
        profile_photo:'',
        img:'',
        create_time:'',
        score:'',
        comment:''
      }
    ]
  },
  // 切换标签
  onChange(event) {
   let _this=this;
   
    if(event.detail.name=='1')
    {
      _this.uncheck();
    }
    else{
      _this.checked();
    }
  },
  showDeatil(e){
    let _this=this;
    let answer_id=e.currentTarget.dataset.id;
    
    wx.navigateTo({
      url: './answer/answer?id='+answer_id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    let _this=this;    
    let jobid=options.jobid;
    wx.request({
      url: 'https://www.yunmosf.top/job/question',
      data:{
        job_id:jobid
      },
      method:'GET',
      success(res){
        let data=JSON.parse(res.data.data);
        
        _this.setData({
          homework:data
        });
        _this.checked();
      }
    });
  },
  /**
   * 获取为批改作业列表
   */
  uncheck(){   
    let _this=this;
    wx.request({
      url: 'https://www.yunmosf.top/job/question/answer/unmarked',
      method:'get',
      data:{
        openid:wx.getStorageSync('openId'),
        job_id:_this.data.homework.id
      },
      success(res){
    
        let data=JSON.parse(res.data.data);
        let length=data.length;
        _this.setData({
          homework_list:data,
          length:length
        });
      }
    })
  },
/**
 * 获取已批改作业
 */
  checked(){
    let _this=this;
   
    
    wx.request({
      url: 'https://www.yunmosf.top/job/question/answer/marked',
      method:'get',
      data:{
        openid:wx.getStorageSync('openId'),
        job_id:_this.data.homework.id
      },
      success(res){
        console.log(res);
        let data=JSON.parse(res.data.data);
        let length=data.length;
        _this.setData({
          homework_list:data,
          length:length
        })
      }
    })
  },
  copy(){
    let _this=this;
    wx.setClipboardData({
      data: _this.data.homework.password,
      })
  },
  /**
   * 停止发布
   */
  btn(){
    let _this=this;
   
    wx.request({
      url: 'https://www.yunmosf.top/job/question/stop',
      method:'GET',
      data:{
        openid:wx.getStorageSync('openId'),
        job_id:_this.data.homework.id,
        stop_status:1
      },
      success(res){
        _this.setData({
          'homework.stop_status':1
        })
        Toast('终止发布成功');
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (opt) {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})